/*
 * Author：杨东宇
 * ReadMe：基于字符串替换实现的下拉框链动算法
 */

var optionsArray = new Array();
function linkSelect(source, target, key) {
    //bank options
    if (optionsArray[key] == undefined) {
        optionsArray[key] = new Array();
        for (var i = 0; i < target.options.length; i++) {
            optionsArray[key][i] = target.options[i].outerHTML;
        }
    }
    //clear options
    target.innerHTML = "";
    //select and add options
    var linkKey = "belongTo=\"" + source.value + "\"";
    var t_options = "";
    for (var i = 0; i < optionsArray[key].length; i++) {
        t_options += (optionsArray[key][i].indexOf(linkKey) == -1) ? "" : optionsArray[key][i];
    }
    if(t_options == "") t_options = "<option value=\"\">请选择</option>";
    var t_select = target.outerHTML;
    t_select = t_select.replace("><", ">" + t_options + "<");
    target.outerHTML = t_select;
}